package com.byt.common.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.byt.common.R;

public class UpdateDialog extends Dialog implements View.OnClickListener {

    private TextView tvTitle;
    private TextView tvMsg;
    private TextView tvSure;
    private ImageView tvDismiss;

    public interface OnDialogButtonClickListener {
        /**
         * 点击按钮的回调方法
         *
         * @param isPositive
         */
        void onDialogButtonClick(boolean isPositive);
    }

    private Activity context;
    private String title;
    private String message;
    private boolean isConfictl;
    private OnDialogButtonClickListener listener;

    public UpdateDialog(Activity context, String title, String message, boolean isConfictl,
                        OnDialogButtonClickListener listener) {
        super(context, R.style.MyDialogStyle);
        this.context = context;
        this.title = title;
        this.message = message;
        this.isConfictl = isConfictl;
        this.listener = listener;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alert_update_dialog);
        setCancelable(isConfictl);//设置点击对话框外部和按返回键都不可以取消
//        setCanceledOnTouchOutside(false);//设置点击对话框外部是否可以取消，默认是不可以取消（但是点返回键可以取消）

        tvTitle = findViewById(R.id.tv_update_title);
        tvMsg = findViewById(R.id.tv_update_msg);
        tvSure = findViewById(R.id.tv_update_sure);
        tvDismiss = findViewById(R.id.img_dismiss_update);
        tvTitle.setText(title);
        tvMsg.setText(message);
        tvMsg.setMovementMethod(ScrollingMovementMethod.getInstance());
        tvSure.setOnClickListener(this);
        tvDismiss.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.tv_update_sure) {//确定按钮
            listener.onDialogButtonClick(true);
        } else if (view.getId() == R.id.img_dismiss_update) {//取消按钮
            listener.onDialogButtonClick(false);

        }
        dismiss();
    }
}